package indi.kider.server.applet.api;

import indi.kider.common.model.apabus.Notice;
import indi.kider.server.applet.model.User;
import indi.kider.server.applet.service.CommService;
import indi.kider.server.applet.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.vankid.common.model.base.CommonResponse;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "notice")
public class NoticController {

    @Autowired
    private NoticeService noticeService;
    @Autowired
    private CommService commService;

    @PostMapping("getNotice")
    public CommonResponse<List<Notice>> getBusInfo(HttpServletRequest request){
        User user = commService.getCurrentUser(request,new User());
        try {
            return CommonResponse.buildGetSuccessResponse(noticeService.getNoticeInfo(user));
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }

    @PostMapping("updateNotice")
    public CommonResponse<String> updateNotice(@RequestBody Notice notice,HttpServletRequest request){
        User user = commService.getCurrentUser(request,new User());
        try {
            return CommonResponse.buildUpdateSuccessResponse(noticeService.updateNotice(notice));
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }


}

